package org.exeed.controller;

import org.exeed.aop.tag.Auth;
import org.exeed.bean.ResultBean;
import org.exeed.entity.PressEntity;
import org.exeed.service.PressContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/press")
public class PressContactController {

    @Autowired
    private PressContactService pressContactService;

    @PostMapping("/save")
    public ResultBean save(@RequestBody PressEntity pressEntity) {

        pressContactService.save(pressEntity);

        return ResultBean.succeed();
    }

    @Auth
    @GetMapping("/selectPages")
    public ResultBean selectPages(@RequestParam("page") Integer page, @RequestParam("size") Integer size,
                                  @RequestParam("key") String key) {
        return ResultBean.succeed(pressContactService.selectList(page, size, key));
    }

    @Auth
    @GetMapping("/getOneById")
    public ResultBean getOneById(@RequestParam("id") Long id) {
        return ResultBean.succeed(pressContactService.selectById(id));
    }

    @Auth
    @GetMapping("/delete")
    public ResultBean delete(@RequestParam("id") Long id) {
        pressContactService.delete(id);
        return ResultBean.succeed();
    }
}
